package web.commons;

import application.authorization.MyRoles;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;


public class SecureLink extends Link {
    private static final long serialVersionUID = 1L;
    Class<? extends WebPage> c;

//    public SecureLink(String id, Class<? extends WebPage> c) {
//        super(id);
//        this.c = c;
//    }

    public SecureLink(String id, Class<? extends WebPage> c, final Action action, String roles) {
        super(id);
        this.c = c;
        MetaDataRoleAuthorizationStrategy.authorize(this, action, roles);
    }

    public SecureLink(String id, Class<? extends WebPage> c, final Action action, MyRoles roles) {
        this(id, c, action, roles.toString());

    }
    //zadam classu a podle toho se nevyrendruje.
    //nebo zadam vlasni zabezpeceni

    public void setSecurity(Action action, String roles) {
        MetaDataRoleAuthorizationStrategy.authorize(this, action, roles);
    }

    @Override
    public void onClick() {
        setResponsePage(c);
    }
}